package org.example.service.impl;

import org.example.mapper.BookMarksMapper;
import org.example.mapper.GroupMapper;
import org.example.pojo.Group;
import org.example.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GroupServiceImpl implements GroupService {
    @Autowired
    private GroupMapper groupMapper;
    @Autowired
    private BookMarksMapper bookMarksMapper;
    @Override
    public List<Group> groupList(Integer userId) {
        return groupMapper.groupList(userId);
    }

    @Override
    public void addGroup(Group group) {
        groupMapper.addGroup(group);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delGroup(Group group) {
        groupMapper.delGroup(group);
        bookMarksMapper.deleteByGroupId(group.getId());
    }
}
